package com.sgcc.pda.frme.protocol.ws.sendbean;

import androidx.annotation.NonNull;

import android.text.TextUtils;

import com.sgcc.pda.frme.protocol.ws.DataConvert;

/**
 * 描述：外设 请求安全单元支持
 * 作者：yangzhi 2020/7/30 17:02
 * 修改描述：
 * 修改人：2020/7/30 17:02
 * 修改版本：
 */
public class SafeSupport2004 {


    /**
     * 请求安全单元数据长度
     */
    private String length;

    /**
     * 安全单元请求数据
     */
    private String data;


    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }


    @NonNull
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (null == length) {
            return null;
        }
        if (length.length() != 4) {
            length = lengthfilling(length, 4);
        }
        sb.append(DataConvert.strReverse(length, 0, length.length()));

        if (null == data) {
            return null;
        }
        sb.append(DataConvert.strReverse(data, 0, data.length()));
        return sb.toString();
    }

    private String lengthfilling(String meterAddress, int length) {
        if (!TextUtils.isEmpty(meterAddress) && meterAddress.length() < length) {
            StringBuilder stringBuffer = new StringBuilder();
            for (int i = 0; i < length - meterAddress.length(); i++) {
                stringBuffer.append("0");
            }
            stringBuffer.append(meterAddress);
            meterAddress = stringBuffer.toString();
            return meterAddress;
        }
        return "";
    }
}
